package com.adams.action.videoupload;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 * 操作结果
 * 
 * @author 903903
 * 
 */
public class Result
{

	public static final Result SUCCESS = new Result("0000", "OK");
	public static final Result FAIL = new Result("9198", "Fail");

	private String resultCode;
	private String resultMessage;

	public Result(String resultCode, String resultMessage)
	{
		this.resultCode = resultCode;
		this.resultMessage = resultMessage;
	}

	public Result(String xml) throws DocumentException
	{
		Document resultDoc = DocumentHelper.parseText(xml);
		Element result = resultDoc.getRootElement();
		this.resultCode = result.elementText("resultCode");
		this.resultMessage = result.elementText("resultMessage");
	}

	public String toXml()
	{
		StringBuilder sb = new StringBuilder();
		sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		sb.append("<result>");
		sb.append("<resultCode>" + resultCode + "</resultCode>");
		sb.append("<resultMessage>" + resultMessage + "</resultMessage>");
		sb.append("</result>");
		return sb.toString();
	}

	public String getResultCode()
	{
		return resultCode;
	}

	public void setResultCode(String resultCode)
	{
		this.resultCode = resultCode;
	}

	public String getResultMessage()
	{
		return resultMessage;
	}

	public void setResultMessage(String resultMessage)
	{
		this.resultMessage = resultMessage;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (obj == null)
		{
			return false;
		}

		if (obj instanceof Result)
		{
			Result result = (Result) obj;
			if (this.resultCode == null || result.getResultCode() == null)
			{
				return false;
			} else
			{
				return this.resultCode.equals(result.getResultCode());
			}
		} else
		{
			return false;
		}
	}

}
